
#include <stdlib.h>
#include <string.h>

#include <public/gen_def.h>
#include <public/gen_endian.h>
#include <public/gen_error.h>
//#include <util/log_agent_const.h>
//#include <util/log_agent.h>

#include "rtmp_const.h"
#include "rtmp_util.h"

// 68bytes FMS key which is used to sign the sever packet.
uint8 rtmp_fms_key[68] =
{
	0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20,
	0x41, 0x64, 0x6f, 0x62, 0x65, 0x20, 0x46, 0x6c,
	0x61, 0x73, 0x68, 0x20, 0x4d, 0x65, 0x64, 0x69,
	0x61, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
	0x20, 0x30, 0x30, 0x31, // Genuine Adobe Flash Media Server 001
	0xf0, 0xee, 0xc2, 0x4a, 0x80, 0x68, 0xbe, 0xe8,
	0x2e, 0x00, 0xd0, 0xd1, 0x02, 0x9e, 0x7e, 0x57,
	0x6e, 0xec, 0x5d, 0x2d, 0x29, 0x80, 0x6f, 0xab,
	0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae
}; // 68

// 62bytes FP key which is used to sign the client packet.
uint8 rtmp_fp_key[62] =
{
	0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20,
	0x41, 0x64, 0x6F, 0x62, 0x65, 0x20, 0x46, 0x6C,
	0x61, 0x73, 0x68, 0x20, 0x50, 0x6C, 0x61, 0x79,
	0x65, 0x72, 0x20, 0x30, 0x30, 0x31, // Genuine Adobe Flash Player 001
	0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8,
	0x2E, 0x00, 0xD0, 0xD1, 0x02, 0x9E, 0x7E, 0x57,
	0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB,
	0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
}; // 62


/////////////////////////////// Inner Interface ///////////////////////////////




////////////////////////////// Outter Interface ///////////////////////////////
int32 rtmp_calc_digest_random_size(RTMP_C1S1_DIGEST* p_digest, int32* p_random_size)
{
	int32   data_size;
	uint8*  p_uint8_data = NULL;

	p_uint8_data = (uint8*)&p_digest->offset;
	data_size = (int32)p_uint8_data[0] + (int32)p_uint8_data[1] + (int32)p_uint8_data[2] + (int32)p_uint8_data[3];

	*p_random_size = data_size % RTMP_C1S1_MAX_DIGEST_OFFSET_SIZE;

	return GEN_S_OK;
}

int32 rtmp_calc_key_random_size(RTMP_C1S1_KEY* p_key, int32* p_random_size)
{
	int32   data_size;
	uint8*  p_uint8_data = NULL;

	p_uint8_data = (uint8*)&p_key->offset;
	data_size = (int32)p_uint8_data[0] + (int32)p_uint8_data[1] + (int32)p_uint8_data[2] + (int32)p_uint8_data[3];

	*p_random_size = data_size % RTMP_C1S1_MAX_KEY_OFFSET_SIZE;

	return GEN_S_OK;
}
